package ngames.com.sushitv.Fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import ngames.com.sushitv.R;
import ngames.com.sushitv.action.SearchFirstAction;
import ngames.com.sushitv.adapter.SearchHistoryAdapter;

/**
 * A simple {@link Fragment} subclass.
 */
public class SearchFirstFragment extends Fragment {
    private RecyclerView historyRecycler;
    private RecyclerView.Adapter historyAdapter;
    private SearchFirstAction searchFirstAction;

    private LinearLayoutManager historyLinearManager;
    private List<String> tags=new ArrayList<>();
    private String[] mVals = new String[]{};
    private View view;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment\
        view=inflater.inflate(R.layout.fragment_search_first, container, false);
        searchFirstAction=new SearchFirstAction(getActivity(),view);
        searchFirstAction.onCreate();
        initView();
        return view;
    }
    private void initView() {
        historyRecycler= (RecyclerView) view.findViewById(R.id.recycler_search_history);
        //trendingFlow= (View_ViewGroup_Flowlayout) view.findViewById(R.id.flow_search_trending);

        initData();
        historyRecycler = (RecyclerView) view.findViewById(R.id.recycler_search_history);
        historyLinearManager = new LinearLayoutManager(getContext());
        //每个item高度一致，可设置为true，提高性能
        historyRecycler.setHasFixedSize(true);
        historyRecycler.setLayoutManager(historyLinearManager);
        initHistoryList();
    }

    public void initData() {

        LayoutInflater mInflater=LayoutInflater.from(getContext());
        for(int i=0;i<mVals.length;i++){
           /* final TextView tv= (TextView) mInflater.inflate(R.layout.view_textview_trending, trendingFlow, false);
            tv.setText(mVals[i]);*/
            tags.add(mVals[i]);
           /* trendingFlow.addView(tv);
            //dynamicTagFlowLayout.addView(tv);
            tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(getActivity(), tv.getText().toString(), Toast.LENGTH_SHORT).show();
                }
            });*/
        }

    }
    public void initHistoryList() {
        List<String> historyList=new ArrayList<>();
        historyList.add("hisroty1");
        historyList.add("hisroty2");
        historyList.add("hisroty3");
        historyList.add("hisroty4");
        historyList.add("hisroty5");
        historyAdapter = new SearchHistoryAdapter(getContext(), historyList);
        historyRecycler.setAdapter(historyAdapter);
    }
}
